package com.jic.manager.mapper;

import com.jic.manager.entity.SysDept;
import com.jic.manager.request.orgcenter.SysDeptTreeRequest;
import com.jic.manager.response.MemStoreResponse;
import com.jic.manager.response.MerchantResponse;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 部门信息表
 * @author : 
 * @email : 
 * @since : 2020-03-20 02:03:20
 * @version : v1.0.0
 */
@Repository
@Mapper
public interface  SysDeptMapper {

    long insert(SysDept sysDept);

    long delete(Long id);

    long update(SysDept sysDept);

    SysDept queryByPrimaryKey(Long id);

    List<SysDept> query(SysDept sysDept);

    List<SysDept> queryPage(@Param("startIndex") int startIndex, @Param("limit") int limit, @Param("sysDept") SysDept sysDept);

    long queryPageCount(SysDept sysDept);

//    List<SysDept> queryTree(SysDeptTreeRequest sysDeptTreeRequest);

    @Select("select * from sys_dept where FIND_IN_SET(id,#{deptIdList})")
    List<SysDept> queryListByIds(@Param("deptIdList") String deptIdList);

//    @Select("SELECT b.id,a.id as aId FROM sys_dept AS a INNER JOIN sys_dept AS b ON b.pid = a.id  HAVING a.id = #{pid};")
//    List<Map<String,Long>> getChilderByPid(@Param("pid") Long pid);

    List<SysDept> getChildeListrByPid(@Param("id") Long id);

    List<SysDept> queryTree(SysDeptTreeRequest sysDeptTreeRequest);

    List<Long> queryTreeIdList(SysDeptTreeRequest sysDeptTreeRequest);

    @Select("select id from sys_dept where FIND_IN_SET(id, getChildLst(#{id}));")
    List<Long> queryChildIdList(@Param("id") Long id);

    List<Long> queryChildListById(Long deptId);

    Long getDeptIdByMsName(@Param("msName")String msName);

    List<Long> queryMerchantIdList(@Param("deptId")Long deptId);


    /*通过商家或店铺deptId查询所属子平台deptId*/
    Long getDeptIdByMsId(SysDept sysDept);

    List<SysDept> queryBlurred(SysDept sysDept);

    List<SysDept> queryUserProviderAuthorDept(@Param("userId") Long userId, @Param("deptId")Long deptId);

    SysDept getDeptIdByStoreId(SysDept dept);

    List<SysDept> getChildDeptList(@Param("userId") Long userId,@Param("deptId") Long deptId);

    List<Long> queryDeptIdListByUserId(@Param("userId") Long userId);

    MemStoreResponse getStoreInfoByDeptId(@Param("deptId") Long deptId);

    List<Long> getDeptIdsByStroreIdOrMerchantIdAndType(@Param("businessIds") List<Long> businessId,@Param("deptType") Integer deptType);

    MerchantResponse getMerchantByDeptId(@Param("Id") Long Id);

    /**
     * 微众商户名称变更 同步修改
     * @param sysDept
     * @return
     */
    long updateDeptNameByBusinessId(SysDept sysDept);

    SysDept getByIdPid(@Param("id") Long id);

    void foreachInsert(List<SysDept> list);
}